<template>
	<view>
		<template v-if="list && list.length">
			<view class="tips">
				<view class="tipsTitle">
					<u-icon class="u-m-r-10 icon"
						name="https://aihelp.oss-cn-hangzhou.aliyuncs.com/public/base/2023/11/13/c4fc9d4dcecb4e4a9cb8bf17a511e221.png"
						size="32"></u-icon>
					解锁后可查看数据信息，请到对应的栏目进行查看。
				</view>
				<view>(要跟下单时的信息一致的筛选条件喔！)</view>
			</view>
			<view class="u-p-t-30">
				<view class="shadow-g u-m-l-20 u-m-r-20 u-m-b-40 item" style="padding: 40rpx 30rpx;border-radius: 20rpx;"
					v-for="(item,index) in list" :key="item.id">
					<view class="flex align-center justify-between">
						<view class="">
							<view class="flex align-center">
								<u-icon
									v-if="item.goodName == '择校报告下载' || item.goodName == '调剂报告下载' || item.goodName == '本人所有可调剂的院校数据' || item.goodName == '解锁所有可调剂的院校数据'"
									size="40"
									name="https://aihelp.oss-cn-hangzhou.aliyuncs.com/public/base/2023/11/14/b267acc23eec49288edaa76584f56891.png"></u-icon>
								<u-icon v-if="item.goodName == '解锁单条智慧信息'" size="40"
									name="https://aihelp.oss-cn-hangzhou.aliyuncs.com/public/base/2023/11/14/49d022d81d9344b5b2ca3542e4061628.png"></u-icon>
								<view class="u-m-l-10 u-font-32">{{item.goodName}}</view>
							</view>
							<view v-if="item.goodName != '本人所有可调剂的院校数据' && item.goodName != '解锁所有可调剂的院校数据'"
								style="font-size: 24rpx;color: #797979;" class="u-m-t-30">
								{{item | handleSchoolValue}}
							</view>
							<view class="u-font-24 color999 u-m-t-30">{{item.createTime}}</view>
						</view>
						<view class="flex-shrink" v-if="item.goodName == '调剂报告下载'">
							<view style="font-size: 24rpx;" @click="chakan(item)" class="buttonText u-m-b-20">
								{{item.freeNum == 2 ? '填写预估分数' : '下载预估报告'}}
							</view>
							<view v-if="item.freeNum != 2" @click="formal(item)" style="font-size: 24rpx;" class="buttonText">
								{{item.freeNum == 1 ? '填写正式分数':'下载正式报告'}}
							</view>
						</view>
						<view class="flex-shrink" v-if="item.goodName == '择校报告下载'">
							<view style="font-size: 24rpx;" @click="zexiaofun(item)" class="buttonText u-m-b-20">
								{{!item.attach ? '选择择校信息' :'下载'}}
							</view>
						</view>
						<view class="flex-shrink" v-if="item.goodName == '解锁单条智慧信息'">
							<view style="font-size: 24rpx;" @click="tjDetail(item)" class="buttonText u-m-b-20">
								调剂详情
							</view>
						</view>
						<view class="flex-shrink" v-if="item.goodName == '本人所有可调剂的院校数据'">
							<view style="font-size: 24rpx;" @click="openAll(item)" class="buttonText u-m-b-20">
								智慧调剂
							</view>
						</view>
						<view class="flex-shrink" v-if="item.goodName == '解锁所有可调剂的院校数据'">
							<view style="font-size: 24rpx;" @click="openWisdom" class="buttonText u-m-b-20">
								智慧调剂
							</view>
						</view>
					</view>
				</view>
			</view>
			<u-loadmore @loadmore="handleReachBottom" :status="status" />
		</template>
		<view v-if="!list || !list.length && !isOne">
			<uni-nodata></uni-nodata>
		</view>
		<u-back-top :z-index="100" :scroll-top="scrollTop"></u-back-top>
	</view>
</template>

<script>
	import {
		panduan,
		getReportSchoolRecently,
		downloadCenterList
	} from "@/api/toolbox.js"
	export default {
		data() {
			return {
				scrollTop: 0,
				isOne: false, //用户是否第一次进入
				status: 'loadmore',
				width: 0,
				height: 0,
				baogao1: true,
				flagyugu: 0,
				baogao2: true,
				adjust: null,
				choose: null,
				list: [],
				psize: 10,
				pindex: 1,
			}
		},
		onLoad() {
			let a = uni.getWindowInfo()
			this.width = a.screenWidth
			this.height = a.screenHeight
		},
		onShow() {
			this.getDate();
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		filters: {
			handleSchoolValue(row) {
				let str = '';
				if (row.attach) {
					str += row.attach.schoolName || '';
					str += row.attach.collageName || '';
					str += row.attach.majorCode || '';
					str += row.attach.majorName || '';
				}
				return str || '暂无择校学校信息';
			}
		},
		computed: {
			handleAdjustValue() {
				let str = "";
				if (this.adjust) {
					str += this.adjust.schoolName || '';
					str += this.adjust.collageName || '';
					str += this.adjust.majorCode || '';
					str += this.adjust.majorName || '';
				}
				return str;
			},
			handleChooseVlaue() {
				let str = '';
				if (this.choose) {
					str += this.choose.schoolName || '';
					str += this.choose.collageName || '';
					str += this.choose.majorCode || '';
					str += this.choose.majorName || '';
				}
				return str;
			}
		},
		onReachBottom() {
			this.handleReachBottom();
		},
		methods: {
			openWisdom() {
				uni.navigateTo({
					url: '/pages/toolbox/adjustReport/index?key=1',
				});
			},
			//智慧调剂
			openAll(row) {
				if (row.otherData) {
					let obj = JSON.parse(row.otherData);
					uni.setStorageSync('chooseArr', JSON.stringify(obj.chooseArr));
					uni.setStorageSync('fraction', JSON.stringify(obj.fraction));
					uni.setStorageSync('information', JSON.stringify(obj.information));
					uni.navigateTo({
						url: '/pages/toolbox/adjustReport/index?key=1',
					});
				} else {
					uni.showToast({
						title: '参数异常，请连续客服！',
						icon: 'none'
					});
				}
			},
			//调剂详情页
			tjDetail(row) {
				let obj = {
					college: row.attach.collegeName,
					collegeCode: row.attach.collegeCode,
					major: row.attach.majorName,
					majorCode: row.attach.majorCode,
					schoolCode: row.attach.schoolCode,
					school: row.attach.schoolName,
					studyType: row.attach.studyType == "1" ? '全日制' : '非全日制'
				}
				uni.navigateTo({
					url: '/pages/school/isomorphism/isomorphismDetail/isomorphismDetail?items=' + JSON.stringify(obj),
				});
			},
			handleReachBottom() {
				if (this.status === 'nomore') return;
				this.pindex++;
				this.getDate();
			},
			getDate() {
				uni.showLoading({
					mask: true
				});
				downloadCenterList({
					"pageSize": this.psize,
					"pageNum": this.pindex
				}).then(res => {
					if (res.data) {
						if (this.pindex === 1) {
							this.list = res.data.rows;
						} else {
							this.list.push(...res.data.rows);
						}
						if (!res.data.rows.length || res.data.rows.length < this.psize) {
							this.status = 'nomore';
						} else {
							this.status = 'loading';
						}
					}

				}).finally(() => {
					uni.hideLoading();
				})
			},
			zexiaofun(row) {
				if (!row.attach) {
					uni.navigateTo({
						url: '/pages/toolbox/chooseSchool/placeOrder?payOrderId=' + row.id,
					});
				} else {
					uni.navigateTo({
						url: "/pages/toolbox/chooseSchool/download?id=" + row.attach.chooseSchoolId
					})
				}
			},
			//正式按钮
			formal(row) {
				let adjustId1 = row.attach?.adjustId1;
				let adjustId2 = row.attach?.adjustId2;
				switch (row.freeNum) {
					case 1:
						//跳转正式生成个性化报告页
						uni.navigateTo({
							url: "/pages/toolbox/adjustReport/xinxi?type=produce&id=" + adjustId2 + '&payOrderId=' + row.id
						})
						break;
					case 0:
						//跳转正式下载页
						uni.navigateTo({
							url: "/pages/toolbox/chooseSchool/tiaojixiazai?type=produce&id=" + adjustId1
						})
						break;
				}
			},
			//预估按钮
			chakan(row) {
				let adjustId2 = row.attach?.adjustId2;
				switch (row.freeNum) {
					case 2:
						//填写信息
						uni.navigateTo({
							url: "/pages/toolbox/adjustReport/xinxi?value=1&payOrderId=" + row.id
						})
						break;
					default:
						//跳到预估下载界面
						uni.navigateTo({
							url: "/pages/toolbox/chooseSchool/tiaojixiazai?type=test&id=" + adjustId2
						})
						break;
				}
				return;
				if (this.flagyugu == 0) {
					if (value == 0) {
						//跳到预估下载界面
						uni.navigateTo({
							url: "/pages/toolbox/chooseSchool/tiaojixiazai"
						})
					}
					if (value == 1) {
						//跳到正式下载界面
						uni.navigateTo({
							url: "/pages/toolbox/chooseSchool/tiaojixiazai"
						})
					}
				}
				if (this.flagyugu == 1) {
					if (value == 0) {
						//跳到预估下载界面
						uni.navigateTo({
							url: "/pages/toolbox/chooseSchool/tiaojixiazai"
						})
					}
					if (value == 1) {
						//跳转正式生成个性化报告页
						uni.navigateTo({
							url: "/pages/toolbox/adjustReport/xinxi?type=produce"
						})
					}
				}
				if (this.flagyugu == 2) {
					if (value == 0) {
						//跳到预估填写信息
						uni.navigateTo({
							url: "/pages/toolbox/adjustReport/xinxi?value=1"
						})
					}
					if (value == 1) {
						//跳到正式填写信息
						uni.showToast({
							title: "请先用预估！",
							icon: "error",
							duration: 2000,
						})
					}
				}
				if (value == 3) {
					uni.navigateTo({
						url: "/pages/toolbox/chooseSchool/download"
					})
				}

				if (this.flagyugu == 3) {
					//有无择校报告
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tips {
		background-color: rgba(255, 255, 221, .8);
		font-size: 24rpx;
		color: #333333;
		padding-left: 70rpx;
		padding-right: 70rpx;
		padding-top: 20rpx;
		padding-bottom: 20rpx;
		border-radius: 0 0 16rpx 16rpx;

		.tipsTitle {
			position: relative;

			.icon {
				position: absolute;
				top: 50%;
				left: -40rpx;
				transform: translate(0, -50%);
			}
		}
	}

	.item {}

	.empty {
		width: 600rpx;
		height: 600rpx;
		margin: 0 auto;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.buttonText {
		background-color: rgba(255, 255, 221, .8);
		color: rgba(245, 153, 35, .8);
		min-width: 125rpx;
		border-radius: 50rpx;
		text-align: center;
		line-height: 50rpx;
		padding-left: 30rpx;
		padding-right: 30rpx;
		flex-shrink: 0;
	}
</style>